package com.glp.work.flow.utils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import lombok.extern.slf4j.Slf4j;

/** 
* 动态表单from校验
* @author  pengjia 
* @version 2020年3月11日 上午11:38:16 
*/
@Slf4j
public class DFVaildUtils {
	
	public static Map<String, String> getRequiredFieldForFormMarkingJson(List<String> formJsons){
		Map<String, String> result = new HashMap<>();
		try {
			for(String jsonStr : formJsons) {
				JSONObject form = JSON.parseObject(jsonStr);
				JSONArray jsonArray = form.getJSONArray("list");
				for(int i=0; i<jsonArray.size(); ++i) {
					JSONObject source = jsonArray.getJSONObject(i);
					String name = source.getString("name");
					String model = source.getString("model");
					if(source.getJSONObject("options").getBooleanValue("required")) {
						result.put(model, name);
					}
				}
			}			
		}catch(Exception e) {
			log.error("表单模板必输项解析异常！", e);
		}
		return result;
	}
}
